<%# Copyright 2020 Stan Grishin <stangri@melmac.net> -%>

<%+vpn-policy-routing/css%>
<%+vpn-policy-routing/js%>

<%-
	local packageName = "vpn-policy-routing"
	local uci = require "luci.model.uci".cursor()
	local sys = require "luci.sys"
	local serviceRunning, serviceEnabled = false, false;
	if sys.call("iptables -t mangle -L | grep -q VPR_PREROUTING") == 0 then
		serviceRunning = true
	end
	if uci:get(packageName, "config", "enabled") == "1" then
		serviceEnabled = true
	end

	if serviceEnabled then
		btn_start_status = true
		btn_action_status = true
		btn_stop_status = true
		btn_enable_status = false
		btn_disable_status = true
	else
		btn_start_status = false
		btn_action_status = false
		btn_stop_status = false
		btn_enable_status = true
		btn_disable_status = false
	end
	if serviceRunning then
		btn_start_status = false
		btn_action_status = true
		btn_stop_status = true
	else
		btn_action_status = false
		btn_stop_status = false
	end
-%>

<%+cbi/valueheader%>
	<div class="cbi-value-field">
		<input type="button" class="btn cbi-button cbi-button-apply" id="btn_start" name="start" value="<%:Start%>"
			onclick="button_action(this)" />
		<span id="btn_start_spinner" class="btn_spinner"></span>
		<input type="button" class="btn cbi-button cbi-button-apply" id="btn_action" name="action" value="<%:Restart%>"
			onclick="button_action(this)" />
		<span id="btn_action_spinner" class="btn_spinner"></span>
		<input type="button" class="btn cbi-button cbi-button-reset" id="btn_stop" name="stop" value="<%:Stop%>"
			onclick="button_action(this)" />
		<span id="btn_stop_spinner" class="btn_spinner"></span>
		&nbsp;
		&nbsp;
		&nbsp;
		&nbsp;
		<input type="button" class="btn cbi-button cbi-button-apply" id="btn_enable" name="enable" value="<%:Enable%>"
			onclick="button_action(this)" />
		<span id="btn_enable_spinner" class="btn_spinner"></span>
		<input type="button" class="btn cbi-button cbi-button-reset" id="btn_disable" name="disable" value="<%:Disable%>"
			onclick="button_action(this)" />
		<span id="btn_disable_spinner" class="btn_spinner"></span>
	</div>
<%+cbi/valuefooter%>

<%-if not btn_start_status then%>
<script type="text/javascript">document.getElementById("btn_start").disabled = true;</script>
<%-end%>
<%-if not btn_action_status then%>
<script type="text/javascript">document.getElementById("btn_action").disabled = true;</script>
<%-end%>
<%-if not btn_stop_status then%>
<script type="text/javascript">document.getElementById("btn_stop").disabled = true;</script>
<%-end%>
<%-if not btn_enable_status then%>
<script type="text/javascript">document.getElementById("btn_enable").disabled = true;</script>
<%-end%>
<%-if not btn_disable_status then%>
<script type="text/javascript">document.getElementById("btn_disable").disabled = true;</script>
<%-end%>
